<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>进货单</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <style type="text/css">
        body {
            background-position: center;
            background-size: cover;
            position: relative;
            font-size: 14px;
        }

        header {
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 99;
            background: #fff;
        }

        .aui-list-view .aui-img-object {
            max-width: 80px;
            height: 80px;
            line-height: 80px;
        }

        .aui-counter-list .aui-radio {
            margin-top: 30px;
        }

        .title2 {
            text-align: center;
            padding: 15px;
            font-size: 18px;
            position: relative;
        }

        .edit {
            position: absolute;
            right: 15px;
            font-size: 12px;
            top: 18px;
            z-index: 999;
        }

        .company-name {
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            background: #fff;
        }

        .company-name .aui-radio {
            margin-top: 6px;
        }

        .aui-radio:checked:after, .aui-radio.aui-checked:after {
            top: 0;
            line-height: 26px;
            height: 26px;
        }

        .aui-radio:checked:before, .aui-radio.aui-checked:before {
            content: "";
        }

        .aui-radio {
            margin: 0 10px;
        }

        .good-info {

            line-height: 1;
        }

        .good-name {
            font-size: 13px;
            line-height: 18px;
        }

        .good-info .aui-list-view-cell:after {
            left: 15px;
        }

        .good-info-list {
            color: #a3a3a3;
            font-size: 12px;
            line-height: 1.4;

        }
        .text-price{
            color: #ff0005;
        }

        .good-info-lists {
            width: 100%;
            padding: 5px 0;
            line-height: 30px;
            font-size: 12px;
        }

        .good-edit {
            font-size: 12px;
            line-height: 1.4;
            position: relative;
            background: #f3f3f3;
            overflow: hidden;
            padding: 8px;
            padding-left: 20px;
            position: relative;
        }

        .aui-icon-unfold {
            position: absolute;
            left: -2px;
            top: 2px;
        }

        .aui-icon-unfold:before {
            color: #000;
        }

        .good-edit .aui-counter {
            position: absolute;
            right: 8px;
            top: 8px;
        }

        .good-edits {
            padding-left: 40px;
            display: none;
        }

        footer {
            position: fixed;
            bottom: 0px;
            background: #fff;
            width: 100%;
            display: none;
        }

        footer .aui-list-view-cell {
            padding: 0 10px;

            text-align: right;
        }

        footer .aui-img-body {
            font-size: 13px;
        }

        footer .aui-list-view-cell:last-child:after {
            border: none;
        }

        footer .aui-list-view:after {
            border: none;
        }

        .shuoming {
            display: inline-block;
            color: #000;
        }

        footer .aui-btn-info {
            background: #327afa;
            border-color: #327afa;
            border-radius: 0px;
        }

        footer .all-checked {
            height: 55px;
            line-height: 55px;
        }

        footer .all-checked #allChecked {
            margin-top: 13px;
        }

        footer .aui-list-view {
            padding: 8px 0;
            margin-bottom: 0px;
        }

        .mui-numbox [class*=btn-numbox], .mui-numbox [class*=numbox-btn] {
            width: 25px;
        }

        .jiage {
            color: #ff0005;
        }

        .good-edit .aui-pull-left {
            margin-top: 4px;
        }

        .all-money {
            color: #ff0005;
        }

        .all-goods {
            overflow: hidden;
            float: left;
        }

        .good {
            margin-bottom: 58px;
        }

        footer.aui-border-t {
            position: fixed;
        }

        .editing {
            display: none;
        }

        .isShoucang {
            width: 90%;
            float: right;
            background: #d7e5ff !important;
            border-color: #d7e5ff !important;
            color: #327afa;
            box-sizing: border-box;
        }

        .mui-table-view .mui-media-object {
            line-height: 80px;
            max-width: 80px;
            height: 80px;

        }

        .mui-table-view .mui-media-object.mui-pull-left {
            margin: 0;
        }

        .mui-table-view-cell p {
            color: #000;
        }

        .myPicker {
            position: fixed;
            bottom: 0;
            -webkit-transform: translateY(400px);
            height: 390px;
            overflow-y: auto;
            -webkit-transition: .5s;
            transition: .5s;
        }

        .pickAnimate {
            -webkit-transform: translateY(00px);
        }

        .colorList {
            font-size: 12px;
            height: 180px;
            /*overflow-y: auto;*/
            margin-bottom: 5px;
            position: relative;
        }

        #scroller li.active {
            border: 1px solid #327afa;
            color: #327afa;
        }

        #wrapper {
            position: absolute;
            z-index: 1;
            top: 0;
            bottom: 0;
            left: 0;
            width: 100%;
            overflow: hidden;
        }

        #scroller {
            position: absolute;
            width: 100%;
        }

        .divColor {
            padding: 0 15px;
        }

        .colorBtn {
            padding: 15px;
            text-align: center;
            color: #fff;
            background: #327afa;
            width: 100%;
            overflow: hidden;
            font-weight: bold;
            position: absolute;
            bottom: 0;
        }

        .proColor {
            position: fixed;
            background: #fff;
            z-index: 9999;
        }

        .proColor .close {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 1px solid #9c9c9c;
            position: absolute;
            right: 5px;
            top: 5px;
            color: #9c9c9c;
            z-index: 100000;
            line-height: 20px;
            text-align: center;
            -webkit-box-sizing: content-box;
        }

        .isJiesuan {
            height: 58px;
            line-height: 58px;
        }

        .jiesuan {
            height: 51px;
            overflow: hidden;
        }

        /*弹起的产品规格选择的的*/
        .spanBefore, .spanAfter, .guige-color {
            float: left;
        }

        .spanBefore, .spanAfter {
            width: 7%;
            position: relative;
        }

        .spanBefore {
            text-align: left;
        }

        .guige-color li {
            float: left;
            padding-right: 30px;
            height: 21px;
            line-height: 21px;
        }

        .divYanse {
            width: 86%;
            overflow: hidden;
            float: left;
            padding: 0 8px;
        }

        #ask-reply-box > span {
            z-index: 2;
        }

        .guige .aui-list-view .aui-list-view-cell {
            padding: 12px 0;
        }

        .guige .aui-list-view {
            margin-bottom: 0;
        }

        .aui-content-padded {
            margin-bottom: 0;
        }

        .divScroll {
            position: relative;
            height: 140px;
            overflow: hidden;
        }

        .shuxing {
            background: #fff;
            margin-bottom: 8px;
        }

        .shuxing li {
            line-height: 35px;
            overflow: hidden;
            padding: 8px 0;
        }

        .chicun {
            margin-right: 3%;
        }

        .mui-numbox {
            padding: 0 26px;
            width: 85px;
        }

        .mui-numbox [class*=btn-numbox] {
            width: 25px;
        }

        .mui-numbox .mui-input-numbox {
            height: 33px;
        }

        .mui-numbox [class*=btn-numbox] {
            width: 25px;
        }

        .kucun {
            margin-right: 3%;
        }

        li.total {
            padding: 15px 0;
            font-weight: 400;
            padding-right: 10px;
        }

        .totalNum, .totalMoney {
            color: #ff3333;
        }

        .all-goods, .good {
            width: 100%;
        }

        .noOrder {
            text-align: center;
            margin-top: 120px;
            display: none;
        }

        .goBuy {
            color: #6faebf !important;
            /*font-size: 25px !important;*/
            /*font-weight: bold;*/
            margin-top: 16px;

        }

        .goBuy span {
            /*display: inline-block;
            box-shadow: 0px 3px 0px 0px #e85858;
            padding-bottom: 6px;*/
        }
    </style>
</head>
<body>
<!-- <header>
    <div class="title2">
        <span>进货单</span>
        <span class="edit " tapmode onclick="edit(this)">编辑</span>
    </div>
</header>--><!-- /header -->
<div class="all-goods ">
    <div class="noOrder">
        <p>进货单暂无商品</p>

        <div class="goBuy" tapmode onclick="goBuy()">
            <div><img src="../image/goshopping.png" style="width:80px;height:80px;" /></div>
            <span style="font-size:16px;">去购物?</span>
        </div>
        <!-- <p class="goBuy" tapmode onclick="goBuy()"><span>去购物?</span></p> -->
    </div>
    <div class="good" id="order-content">

        <!--商品订单列表-->
        <!--进货单列表        <div class="good-info">
                    <div class="company-name">
                        <input class="aui-pull-left aui-radio aui-radio-info allCompany" id="p" type="checkbox">
                        <label class="name" for="p">潮纺花料印刷有限公司</label>
                    </div>
                    <ul class="aui-list-view">

                        <li class="aui-list-view-cell aui-img aui-counter-list">
                            <input class="aui-pull-left aui-radio aui-radio-info" type="checkbox">
                            <img class="aui-img-object aui-pull-left" src="../image/shili.jpg">

                            <div class="aui-img-body">
                                <span class="good-name aui-ellipsis-2">这个是商品标个是商品标题这个是商标题这个是商标题这个是商品标题</span>

                                <div class="good-info-lists">
                                    <div class="good-info-list aui-ellipsis-2">颜色分类：粉红色、粉红色、粉红色、粉红色、粉红色、粉红色、粉红色</div>
                                    <div class=" aui-pull-left">￥<span class="good-pirce">5.5</span></div>
                                    <div class=" aui-pull-right">x<span class="good-count">12</span></div>
                                </div>
                            </div>
                            <div class="aui-counter-box good-edits">
                                <div class="good-edit">
                                    <i class="aui-iconfont aui-icon-unfold aui-pull-right comment-icon "></i>

                                    <div class="good-edit-info aui-ellipsis-2" tapmode onclick="showPicker()">
                                        颜色分类：粉红色、粉红色、粉红色、粉红色、粉红色、粉红色、粉红色、粉红色
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="aui-list-view-cell aui-img aui-counter-list">
                            <input class="aui-pull-left aui-radio aui-radio-info" type="checkbox">
                            <img class="aui-img-object aui-pull-left" src="../image/shili.jpg">

                            <div class="aui-img-body">
                                <span class="good-name aui-ellipsis-2">这个是商品标个是商品标题这个是商标题这个是商标题这个是商品标题</span>

                                <div class="good-info-lists">
                                    <div class="good-info-list aui-ellipsis-2">颜色分类：粉红色、粉红色、粉红色、粉红色、粉红色、粉红色、粉红色</div>
                                    <div class=" aui-pull-left">￥<span class="good-pirce">5.5</span></div>
                                    <div class=" aui-pull-right">x<span class="good-count">12</span></div>
                                </div>
                            </div>
                            <div class="aui-counter-box good-edits">
                                <div class="good-edit">
                                    <i class="aui-iconfont aui-icon-unfold aui-pull-right comment-icon "></i>

                                    <div class="good-edit-info aui-ellipsis-2" tapmode onclick="showPicker()">
                                        颜色分类：粉红色、粉红色、粉红色、粉红色、粉红色、粉红色、粉红色、粉红色
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>-->
    </div>
</div>
<footer class="aui-border-t">
    <div class="aui-col-xs-3 all-checked">
        <input class="aui-pull-left aui-radio aui-radio-info" id="allChecked" type="checkbox">全选
    </div>
    </div>
    <div class="aui-col-xs-6">
        <ul class="aui-list-view edited">
            <li class="aui-list-view-cell aui-img isNum ">
                <div class="aui-img-body">
                    合计：<span class="all-money" style="font-size: 15px;">￥0.00</span>
			                <span class="shuoming" style="color:#a3a3a3;font-size: 11px;">
								<span id="goodsNumber">0</span>件不含运费
			                </span>
                </div>
            </li>
        </ul>

        <div class="  myBtn isShoucang editing" tapmode onclick="moveToFavorite()">移至收藏夹</div>
    </div>
    <div class="aui-col-xs-3">
        <div class="myBtn isJiesuan edited" tapmode onclick="orderSubmit()">结算</div>
        <div class="myBtn isDele editing" id="orderDelete">删除</div>
    </div>
</footer>
<!-- 商品颜色 -->
<div class="myPicker proColor " id="spec-cont">
    <div id="ask-reply-box">
        <span class="aui-iconfont aui-icon-roundclose aui-pull-right" tapmode onclick="hidePicker()"></span>
    </div>
    <!-- 产品的规格选择 -->
    <div class=" guige ">
        <div class="aui-content-padded">
            <ul class="aui-list-view  aui-border-b" id="spec-content">
                <!--上面spec1属性-->
            </ul>
            <div class="divScroll">
                <div id="wrapper">
                    <div id="scroller">
                        <ul class="shuxing " id="scroller-content">
                            <!--下面spec2属性-->
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <ul class="jiesuan">
            <li class="total aui-text-right aui-border-t">共<span class="totalNum">0</span>条 <span
                    class="totalMoney">￥0.00</span>
            </li>

        </ul>
    </div>
    <div class="colorBtn" tapmode onclick="madeSure()">
        确 定
    </div>
</div>
<!--商品订单列表-->
<script id="order-template" type="text/x-dot-template">
    {{ for (var i in it) { }}
    <div class="good-info">
        <div class="company-name">
            <input class="aui-pull-left aui-radio aui-radio-info allCompany" id="p" type="checkbox" style="margin-left: 15px;margin-right: 13px;">
            <label class="name " for="p">{{=it[i].companyName}}</label>
        </div>
        <ul class="aui-list-view">
            {{ for (var is in it[i].goods) { }}
            <li class="aui-list-view-cell aui-img aui-counter-list proLsit">
                <input class="aui-pull-left aui-radio aui-radio-info" name="ordercheck" type="checkbox"
                       value="{{=it[i].goods[is].itemid}}">
                <img class="aui-img-object aui-pull-left" src="{{=it[i].goods[is].thumb}}">

                <div class="aui-img-body">
                    <span class="good-name aui-ellipsis-2">{{=it[i].goods[is].title}}</span>

                    <div class="good-info-lists">
                        <div class="good-info-list aui-ellipsis-2">{{=it[i].goods[is].spec}}</div>
                        <div class=" aui-pull-left text-price">￥<span class="good-pirce">{{=it[i].goods[is].price}}</span></div>
                        <div class=" aui-pull-right" style="color:#666;">x<span class="good-count">{{=it[i].goods[is].goodsNumber}}</span>
                        </div>
                    </div>
                </div>
                <div class="aui-counter-box good-edits">
                    <div class="good-edit">
                        <i class="aui-iconfont aui-icon-unfold aui-pull-right comment-icon "></i>

                        <div class="good-edit-info aui-ellipsis-2" tapmode
                             onclick="showPicker(this,{{=it[i].goods[is].itemid}})">
                            {{=it[i].goods[is].spec}}
                        </div>
                    </div>
                </div>
            </li>
            {{ } }}
        </ul>
    </div>
    {{ } }}
</script>
<script id="spec-template" type="text/x-dot-template">
    <li class="aui-list-view-cell aui-img">
        <img class="aui-img-object aui-pull-left" src="" id="cat_pic">

        <div class="aui-img-body">
            <div class="aui-ellipsis-2">
                {{=it.title.title}}
            </div>
            <p class="guige-price">￥{{=it.areamoney.min}}-￥{{=it.areamoney.max}}</p>
        </div>
    </li>
    <li class="aui-list-view-cell aui-img">
                            <span class="spanBefore aui-iconfont aui-icon-left guigehuise" tapmode
                                  onclick="myScroll.prev()">

                            </span>

        <div class="divYanse" id="yanse">
            <div class="yanse">
                <ul class="guige-color">
                    {{ for(var i in it.cat){ }}
                    <li {{? i== 0}} class="active" {{?}} data-pic="{{=it.cat[i].pic}}" data-num="aa{{= i}}"
                        onclick="getother(this)">{{=it.cat[i].spec1}}
                    </li>
                    {{ } }}
                </ul>
            </div>
        </div>
							<span class="spanAfter aui-iconfont aui-icon-right guigehuise" tapmode
                                  onclick="myScroll.next()">

                            </span>
    </li>
</script>
<script id="scroll-template" type="text/x-dot-template">
    {{ for(var i in it.content){ }}
    <ul class="shuxing aa{{= i}} aa_all" {{? i !=0 }} style="display:none;" {{?}}>
        {{ for(var j in it.content[i]){ }}
        <li class="aui-border-b aa{{= i}}" data-specid="{{=it.content[i][j].id}}">
            <div class="chicun  aui-pull-left">{{=it.content[i][j].spec2}}</div>
            <div class="danjia  aui-pull-left">单价:￥{{=it.content[i][j].money}}</div>
            <div class="mui-numbox  aui-pull-right" data-numbox-min='0' data-numbox-max='{{=it.content[i][j].amount}}'>
                <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
                <input data-money="{{=it.content[i][j].money}}" data-id="{{=it.content[i][j].id}}"
                       class="mui-input-numbox spec" type="number"
                       value="{{? it.content[i][j].goodsNumber}}{{=it.content[i][j].goodsNumber}}{{??}}0{{?}}"
                       onchange="getnumber()"/>
                <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
            </div>
            <div class="kucun aui-pull-right">
                <span>库存:{{=it.content[i][j].amount}}</span>
            </div>
        </li>
        {{ } }}
    </ul>
    {{ } }}
</script>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/myInfo.js"></script>
<script type="text/javascript" src="../script/mui.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript" src="../script/iscroll.js"></script>
<script type="text/javascript" src="../script/index.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript">
    var  itemsData;
    apiready = function () {
        getStorageAll();
        //接收监听
        api.addEventListener({
            name: 'reGetMyInfo'
        }, function (ret) {
            if (ret && ret.value) {
                getStorageAll();
                cartList(user_id, user_name);
            }
        });
        //接收监听
        api.addEventListener({
            name: 'updateCart'
        }, function (ret) {
            if (ret && ret.value) {
                getStorageAll();
                cartList(user_id, user_name);

                api.execScript({
                    name:'root',
                    script:'edit()'
                });
                edit('update');
            }
        });
//        showLoading();
        //检测用户名
        if (!user_id) {
            openTo('loginPass_win');
            return false;
        }
        cartList(user_id, user_name);
    }

    //suadd start
    function cartList(user_id, user_name) {
        // showLoading();
        var data = {
            userId: user_id,
            userName: user_name,
        };
        var url = 'Mallcart/cartList';
        ajaxRequest(url, 'post', data, function (ret, err) {
            // hideLoading();
            if (ret.status == 1) {
                itemsData=new Array();
                for(var i in ret.msg){
                    if(ret.msg[i].goods){
                        for(j in ret.msg[i].goods){
                            itemsData.push(ret.msg[i].goods[j]);
                        }
                    }
                }

                $("footer").css({"display": "block"});
                $(".noOrder").css({"display": "none"});
//                $("#expressAll").text(ret.msg.expressAll);
//                $("#goodsPrice").text(ret.msg.goodsPrice);
//                $("#priceAll").text(ret.msg.priceAll);
                var content = $api.byId('order-content');
                var tpl = $api.byId('order-template').text;
                var tempFn = doT.template(tpl);
                $api.html(content, '');
                $api.html(content, tempFn(ret.msg));

                checkAll();


                api.execScript({
                    name:'root',
                    script:'showCartButton()'
                });
            } else {
                $("#order-content").empty();
                $(".noOrder").css({"display": "block"});
                $("footer").css({"display": "none"});

                api.execScript({
                    name:'root',
                    script:'hideCartButton()'
                });
//                api.toast({
//                    msg: '购物车为空',
//                    duration: 2000,
//                    location: 'bottom'
//                });
            }

        });
    }

    //获取产品规格分类
    function getspec(itemid) {
        $api.setStorage('_itemid', itemid);
        showLoading();
        var data = {
            goodsId: itemid,
            userId: user_id,
        };
        var url = 'Mallcart/goodsSpec';
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                //spec1
                var content = $api.byId('spec-content');
                var tpl = $api.byId('spec-template').text;
                var tempFn = doT.template(tpl);
                $api.html(content, '');
                $api.html(content, tempFn(ret.msg));
                //spec2
                var content2 = $api.byId('scroller');
                var tpl2 = $api.byId('scroll-template').text;
                var tempFn2 = doT.template(tpl2);
                $api.html(content2, '');
                $api.html(content2, tempFn2(ret.msg));
                pic = ret.msg.cat[0].pic;
                // id = ret.msg.cat[0].id;
                $('#cat_pic').attr('src', pic);
                // getspecContent(itemid);
                getscroll();
                mui('.mui-numbox').numbox();
                getnumber();
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
        hideLoading();
    }

    //更新购物车
    function updateCart() {
        var str = "";
        var num = 0;
        var money = 0;
        var id = 0;
        var itemid = $api.getStorage('_itemid');
        //清除缓存
        $api.rmStorage('_itemid');
        $(".spec").each(function () {
            num = $(this).val() * 1;

            money = $(this).attr("data-money");
            id = $(this).attr("data-id");
            str += id + "_" + num + "_" + money + "-";

        });
        var data = {
            goodsId: itemid,
            str: str,
            userId: user_id,
        };
        var url = 'Mallcart/updateCart';
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                //发送监听
                api.sendEvent({
                    name: 'updateCart',
                    extra: {
                        key: 'true'
                    }
                });
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
                edit("update");
                api.execScript({
                    name: 'root',
                    script: "edit()"
                })
            } else {
                //发送监听
                api.sendEvent({
                    name: 'updateCart',
                    extra: {
                        key: 'true'
                    }
                });
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
    }

    //删除购物车
    $("#orderDelete").click(function () {
        if (window.confirm('确定删除吗')) {
            var goodsIds = goodsCheck();
            var data = {
                goodsIds: goodsIds,
                userId: user_id,
            };
            var url = 'Mallcart/deleteCart';
            ajaxRequest(url, 'post', data, function (ret, err) {
                if (ret.status == 1) {
                    //发送监听
                    api.sendEvent({
                        name: 'updateCart',
                        extra: {
                            key: 'true'
                        }
                    });
                    edit("update");
                    api.execScript({
                        name: 'root',
                        script: "edit()"
                    })
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                } else {
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        }
        ;
    });

    //提交到订单列表
    function orderSubmit() {
        $api.rmStorage('_itemId');
        $api.rmStorage('_str');
        $api.rmStorage('_companyname');
        
        var goodsIds = goodsCheck();
        if (goodsIds == '') {
            return false;
        }
        api.openWin({
            name: 'orderComfirm',
            url: 'orderComfirm.html',
            pageParam: {
                goodsIds: goodsIds
            },
        });

    }

    //获取选中商品
    function goodsCheck() {
        var goodsIds = '';
        $(".all-goods").find("input[type='checkbox']").each(function () {
            if (!$(this).hasClass("allCompany") && $(this).prop("checked")) {
                goodsIds += $(this).val() + '-';
            }
        })
        return goodsIds;
    }

    //spec1 控制spec2 显示
    function getother(obj) {
        var data_num = $(obj).attr("data-num");
        $('.aa_all').hide();
        $('.' + data_num + '').show();
    }

    //统计总数量和总价格
    function getnumber() {
        var sum = 0, nums = 0;
        $(".spec").each(function () {
            num = $(this).val() * 1;
            money = $(this).attr("data-money");
            sum += num * money;
            nums += num;
        });
        sum = sum.toFixed(2);
        $('.totalNum').text(nums);
        $('.totalMoney').text('¥' + sum);
    }

    //产品规格滑动区域
    function getscroll() {
        //颜色宽度
        $(".yanse").width(getWidth() + 30);
        // 颜色滚动的
        loadYanse();
        //区域滚动,库存选择那些
        AttrScroll = new IScroll("#wrapper", {
            probeType: 3,
            mouseWheel: true,
            click: true
        });
    }

    //suadd end


    // mui遮罩
    var mask = mui.createMask(hidePicker);
    /*$(function () {
     //颜色宽度
     $(".yanse").width(getWidth());
     // 颜色滚动的
     loadYanse();
     //区域滚动
     myscroll = new IScroll("#wrapper", {
     probeType: 3,
     mouseWheel: true,
     click: true
     });
     })*/
    // 颜色滚动的
    function loadYanse() {
        myScroll = new IScroll('#yanse', {
            scrollX: true,
            scrollY: false,
            mouseWheel: true,
            vScroll: false,
            click: true,
            snap: true,
            beforeScrollStart: function (e) {
                if (this.absDistX > (this.absDistY + 5 )) {
                    // user is scrolling the x axis, so prevent the browsers' native scrolling
                    e.preventDefault();
                }
            }
        });
    }
    // 计算颜色的宽度
    function getWidth() {
        var height = 0;
        $(".yanse").find("li").each(function () {
            height += $(this).outerWidth(true);
        })
        return height + 30;
    }

    function funcGotoBakHome(index) {
        getStorageAll();
        if (user_id) {
            api.execScript({
                name: 'root',
                script: 'randomSwitchBtnBakHome(' + index + ')'
            });
        } else {
            openTo('login_win');
        }
    }
    //提示信息
    function message() {
        api.toast({
            msg: '暂不支持',
            duration: 2000,
            location: 'middle'
        });
    }
    // 单击编辑
    function edit(type) {
        if (type == "editing") {
            // 单击编辑，编辑状态
            $(".good-edits").css({"display": "block"});
            $(".editing").css({"display": "block"});
            $(".edited").css({"display": "none"});
            //把输入框的复制

        } else {
            // 单击完成，完成状态
            $(".good-edits").css({"display": "none"});
            $(".editing").css({"display": "none"});
            $(".edited").css({"display": "block"});
        }
    }
    //编辑状态的数量框变化
    $(document).on("change", ".goodNum", function () {
        var goodNum = $(this).val();
        $(this).parents("li").find(".good-count").eq(0).text(goodNum);
    })
    //结算下面的全选，所有的都是全选
    $(document).on("click", "#allChecked", function () {
        $(".all-goods").find("input:checkbox").prop("checked", $(this).prop("checked"));
        //改变总价格和数量
        change();
    })
    //单击选选择框
    $(document).on("click", ".all-goods input:checkbox", function () {
        if ($(this).hasClass("allCompany")) {
            var $companyGoods = $(this).parents(".good-info");
            $companyGoods.find("input:checkbox").prop("checked", $(this).prop("checked"));
        } else {
            // 单击的是商品的选择框
            //判断处理这个公司是否全选了
            checkCompanyAll(this);
        }
        //处理判断是否是全选了
        checkAll();
        //改变总价格和数量
        change();
    })

    //改变总价格和数量
    function change() {
        //单击的是公司名的选择框
        var totalMoney = 0;
        var totalCount = 0;
        $(".good ").find(".proLsit").each(function () {
            if ($(this).find("input:checkbox").prop("checked")) {
                totalMoney += parseFloat($(this).find(".good-pirce").text());
            }
        })
        $(".all-money").text('¥'+totalMoney.toFixed(2));
        //全部数量
        $(".good ").find(".proLsit").each(function () {
            if ($(this).find("input:checkbox").prop("checked")) {
                totalCount += parseFloat($(this).find(".good-count").text());
            }
        })
        $("#goodsNumber").text(totalCount);
    }


    //选择框改变是判断是否是全部有选择，改变全选的状态，处理的是结算的全算
    function checkAll() {
        var num = 0, len = $(".all-goods").find("input:checkbox").length;
        $(".all-goods").find("input:checkbox").each(function () {
            if ($(this).prop("checked")) {
                num++;
            } else {
                return false;
            }
        })
        if (num == len) {
            //表示全选所有商品
            $("#allChecked").prop("checked", true);
            return true;
        } else {
            $("#allChecked").prop("checked", false);
            return false;
        }
    }
    //判断公司是否全选
    function checkCompanyAll(thisObj) {
        var num = 0,
                len = $(thisObj).parents("ul").find("input:checkbox").length;
        $(thisObj).parents("ul").find("input:checkbox").each(function () {
            if ($(this).prop("checked")) {
                num++;
            } else {
                return false;
            }
        })
        if (num == len) {
            //表示全选一个公司所有商品
            $(thisObj).parents(".good-info").find(".allCompany").prop("checked", true);
        } else {
            $(thisObj).parents(".good-info").find(".allCompany").prop("checked", false);
        }
    }
    // 关闭的x号
    $(document).on("click", ".close", function () {
        hidePicker();
        mask.close();
    })
    // 显示遮罩
    function showPicker(obj,itemid) {
        var itemData;
        if(!itemsData)return;
        for(i in itemsData){
            if(itemid==itemsData[i].itemid){
                itemData=itemsData[i];
                break;
            }
        }

        showLoading();
        url = 'mall/spec/goodsId/' + itemid;
        ajaxRequest(url, 'get', {}, function (ret, err) {
            hideLoading();
            if(ret.status==1){
                var specData=ret.msg;

                api.openFrame({
                    name: 'proAttribute_frm',
                    url: './proAttribute_frm.html',
                    animation:{
                        type:"none"             
                    },
                    pageParam:{
                        itemData:itemData,
                        specData:specData,
                        selectedSpecs:itemData.str,
                        onlyCart:true
                    }
                });                
            }else{
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });

    }
    // 关闭遮罩
    function hidePicker() {
        removeBodyLayer();
        // 关闭是，显示出上下
        $(".myPicker").removeClass("pickAnimate");
        mask.myclose();
        api.sendEvent({
            name: "closeColor",
            extra: {
                close: true
            }
        })
    }
    // 产品规格颜色选择

    $(document).on("click", ".guige-color li", function () {
        $(this).parent().find("li").removeClass("active");
        $(this).addClass("active")
    })
    function madeSure() {
        hidePicker();
        updateCart();
    }
    /**
     * add by moqin
     * 没有商品时候去购物
     */
    function goBuy() {
        api.execScript({
            name: "root",
            script: 'randomSwitchBtnBakHome(0)'
        })
    }
    //移到收藏夹
    function moveToFavorite() {
        showLoading();
        var goodsIds=[];
        $(".good").find("input[type='checkbox']").each(function(){
            if(!$(this).hasClass("allCompany")){
                if($(this).prop("checked")){
                    goodsIds.push($(this).val());
                }
            }
        });
        getStorageAll();
        if(goodsIds.length){
            var url = 'Cart/addFavorites?username='+user_name;
           ajaxRequest(url, 'post', {
                itemids:goodsIds.join(',')
           }, function (ret, err) {
                hideLoading();
                if(ret.status){

                    api.execScript({
                        name:'root',
                        script:'edit()'
                    });
                    edit('update');

                    api.toast({
                        msg: '已添加至收藏夹',
                        duration: 2000,
                        location: 'bottom'
                    });
                }else{
                     api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
           });
        }
    }
</script>
</html>